package com.itmd.dao;

import com.itmd.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {






    @Insert("insert into user values (#{id},#{username},#{password});")
    void add(User user);


    @Update("update user set password=#{password} where id=#{id}")
    void update(User user);

    @Update("update user set username=#{username} where id=#{id}")
    void updateUsername(User user);

    @Delete("delete from user where id=#{id}")
    void delete(Integer userid);

    @Select("select * from user")
    List<User> findAll();

    @Select("select * from  user where id=#{id}")
    User findById(Integer id);

    @Select("select * from user where id=#{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(
                    property = "orderslist",
                    column = "id",  //查询订单 所需要的字段
                    javaType = List.class,
                    many = @Many(select = "com.itmd.dao.OrderMapper.findOrdersByUid" )
            )
    })
    List<User> findUserAndOrdersAll(Integer id);


    @Select("select * from user")
    @Results({
            @Result(id=true ,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(
                    property = "rolelist",
                    javaType = List.class,
                    column = "id",
                    many = @Many(select = "com.itmd.dao.RoleMapper.findRoleByUserid")
            )
    })
    List<User> findeUserAndRoleAll();


}
